package AdminController

import (
	"el/app/libs"

	"github.com/labstack/echo/v4"
	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/disk"
	"github.com/shirou/gopsutil/mem"
)

type SystemController struct {
}

func (my *SystemController) Cpu(c echo.Context) error {
	list, err := cpu.Info()
	if err != nil {
		return libs.Error(c, 1, err.Error())
	}
	if len(list) == 0 {
		return libs.Error(c, 1, "异常")
	}
	return libs.Ok(c, list[0])
}

func (my *SystemController) Ram(c echo.Context) error {
	info, err := mem.VirtualMemory()
	if err != nil {
		return libs.Error(c, 1, err.Error())
	}
	return libs.Ok(c, info)
}

func (my *SystemController) Disk(c echo.Context) error {
	info, err := disk.Usage("/")
	if err != nil {
		return libs.Error(c, 1, err.Error())
	}
	return libs.Ok(c, info)
}
